using UnityEngine;
public class PlayerController : MonoBehaviour
{
    // open param
    [SerializeField] float walkSpeed;

    // cache param
    private float horizontalInputRaw;
    private float verticalInputRaw;

    void Update()
    {
        CalcInputVal();
        Vector3 dir = new Vector3(horizontalInputRaw, 0, verticalInputRaw);
        MovePosition(transform, dir, walkSpeed, Time.deltaTime);
    }

    private void CalcInputVal()
    {
        horizontalInputRaw = Input.GetAxisRaw("Horizontal");
        verticalInputRaw = Input.GetAxisRaw("Vertical");
    }
    private Vector3 MovePosition(Transform selfTrans, Vector3 dir, float xzspeed, float deltaTime)
    {
        // x-z plane
        Vector3 currPos = selfTrans.position;
        dir.Set(dir.x, 0, dir.z);

        // y axis
        RaycastHit hit;
        bool isContacted = Physics.Raycast(currPos, Vector3.down, out hit, 1);
        Debug.DrawLine(currPos, currPos + Vector3.down, Color.cyan);
        if (isContacted)
        {
            Vector3 rotateAxis = Vector3.Cross(selfTrans.up, selfTrans.forward);
            float signedAngle = Vector3.SignedAngle(hit.normal, Vector3.up, rotateAxis);
        }
        return currPos;
    }
}
